﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using AIthin.Neuro;

namespace AIthin.Model
{
    public partial class NewNetworkForm : Form
    {
        /// <summary>
        /// Neurons network without layers.
        /// </summary>
        public Network network; 

        /// <summary>
        /// Constructor
        /// </summary>
        public NewNetworkForm()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {

   //         int Inputs = int.Parse(textBoxInputs.Text);
            int NCount = int.Parse(textBoxNeurons.Text);
            int Outputs = int.Parse(textBoxOutputs.Text);

            //calculate input 
            comboBoxSize_SelectedIndexChanged(sender, e);

            int Size = int.Parse(comboBoxSize.SelectedItem.ToString());

            int Inputs = Size * Size;

            textBoxInputs.Text = Inputs.ToString();
            this.Refresh();

            String Name = textBoxName.Text 
                + "-" + Inputs.ToString() 
                + "-" + NCount.ToString()
                + "-" + Outputs.ToString() 
                + ".nw1";
            network = new Network(NCount, Inputs, Outputs);
             network.Save(AIthin.Model.Properties.Settings.Default.WorkingPath + "\\" + Name);
            MessageBox.Show("Network " + Name + " saved.");
            this.Hide();

            NeuroNetworkForm NF1 
                = new NeuroNetworkForm(AIthin.Model.Properties.Settings.Default.WorkingPath, Name);
            NF1.MdiParent = this.MdiParent;
 //           NF1.LoadNetworkFile(AIthin.Model.Properties.Settings.Default.WorkingPath, Name);
            NF1.Show();

            this.Close();

                       
        }

        private void NewF_NetworkForm_Load(object sender, EventArgs e)
        {

        }

        private void comboBoxSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            int Size = int.Parse(comboBoxSize.SelectedItem.ToString());
            int Inputs = Size * Size;
            textBoxInputs.Text = Inputs.ToString();
            this.Refresh();
        }
    }
}
